<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="项目名称">
          <el-input v-model="queryParam.qry_projectname" placeholder="" @keyup.enter.native="doQuery"></el-input>
        </el-form-item>
        <el-form-item label="项目级别">
          <el-select v-model="projectlevelList" multiple placeholder="请选择项目级别" style="width:190px">
            <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目经理">
          <el-input v-model="queryParam.qry_projectmanager" placeholder="工号或姓名" @keyup.enter.native="doQuery">
          </el-input>
        </el-form-item>
        <el-form-item label="部门名称">
          <el-select style="width:180px" v-model="createdepart" placeholder="请选择部门名称" filterable collapse-tags clearable multiple @change="doQueryConcatCreateDepart">
            <el-option v-for="item in codeModel.deptCommonCodeList" :key="item.code" :label="item.name" :value="item.code" />
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" :isDisplayAdd="false" :isDisplayDeleteBatch="false" @exportExcel="doExportExcel" :isDisplayExport="false" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :row-style="tableRowStyle" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <!-- <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column> -->
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="deptname" label="所属部门" width="120px" sortable="custom" sort-by="deptname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectcode" label="项目编号" width="150px" sortable="custom" sort-by="projectcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectname" label="项目名称" min-width="400px" sortable="custom" sort-by="projectname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectlevel" label="项目级别" width="150px" sortable="custom" sort-by="projectlevel" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmanager" label="项目经理" width="150px" sortable="custom" sort-by="projectmanager" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="finishdate" label="立项结束日期" width="120px" sortable="custom" sort-by="signdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="单据状态" width="100px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="daynum" label="超期天数" width="100px" sortable="custom" sort-by="daynum" align="center">
            <template slot-scope="scope">
              <el-tag :type="scope.row.daynum < 1 ? 'success' : 'danger'">{{ scope.row.daynum }}</el-tag>
            </template>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
      <index-comp ref="indexComp" :projectcode="projectcode"></index-comp>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import { validateNull } from '@tapui/utils/validate'
import tlEdit from './edit'
import indexComp from '@/views/mpm/projectInfo/indexComp'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
import { filterObjectNull, rmbFormat } from '@tapui/utils/util'
export default {
  name: 'mpmProject',
  mixins: [mixin_list],
  components: { tlEdit, indexComp },
  data() {
    return {
      projectlevelList: [],
      description: '项目立项-列表查询',
      urlPrefix: '/mpm/projectpolymerization/',
      url: {
        queryCodeList: '/mpm/projectpolymerization/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'mpmproject.ABNORMALSTATE',
        sord: 'desc'
      },
      createdepart: [],
      projectcode: ''
    }
  },
  methods: {
    /** 获取查询参数 */
    getQueryParams() {
      let param = {}
      if (this.projectlevelList) {
        param.qry_projectlevel = this.projectlevelList.join(',')
      }
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
      }
      Object.assign(param, this.queryParam, this.sorterInfo, this.filtersInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      param.qry_projectstate = 1
      param.qry_permission = this.$route.params.qry_permission
      param.qry_overdue = this.$route.params.qry_overdue
      param.qry_category = 'appointment'
      return filterObjectNull(param)
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    /** 列表数据加载开始 */
    loadData(paramMap) {
      // 得到加载分页
      if (validateNull(paramMap) === false && Object.keys(paramMap).indexOf('currentPage') > -1) {
        this.pageInfo.currentPage = paramMap['currentPage']
      }
      if (!this.beforeLoadData()) return
      // 查询条件
      var params = this.getQueryParams()
      // 数据查询
      this.loading = true
      getAction('/mpm/projectpolymerization/queryAppointmentOverDate', params)
        .then(res => {
          if (res.success) {
            this.datas = res.result.dataList
            this.pageInfo.totalCount = res.result.totalCount
            // 初始化自定义列
            if (typeof this.$refs.toolbar !== 'undefined') {
              this.$refs.toolbar.doInitTableColumn()
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterLoadData()
          this.loading = false
        })
        .catch(err => {
          this.loading = false
        })
    },
    // 行颜色
    tableRowStyle(row, index) {
      if (row.row.abnormalstate === 30) {
        return { 'background-color': 'rgb(235,75,75)', color: 'white' }
      } else if (row.row.abnormalstate === 20) {
        return { 'background-color': 'rgb(242,166,175)', color: 'white' }
      } else if (row.row.abnormalstate === 10) {
        return { 'background-color': 'rgb(250,205,145)' }
      } else if (row.row.abnormalstate === 15) {
        return { 'background-color': '#0000FF', color: 'white' }
      }
    },
    // 双击打开项目运作页面
    doRowDbClick(row, column, event) {
      // 审批完成跳转到详情页
      this.projectcode = row.projectcode
      this.$nextTick(() => {
        this.$refs.indexComp.id = row.id
        this.$refs.indexComp.visible = true
      })
    },
    // 部门名称多选框
    doQueryConcatCreateDepart(data) {
      if (data.length > 0) {
        this.queryParam.qry_deptcommoncode = data
          .map((item) => {
            return "'" + item + "'"
          })
          .join(',')
      } else {
        this.queryParam.qry_deptcommoncode = null
      }
    }
  }
}
</script>

<style scoped>
.app-container >>> .el-table tbody tr:hover > td {
  background-color: transparent !important;
}
</style>

